#include "CalibrateWidget.h"

void CalibrateWidget::setup(QString text) {
	textView = new QLabel(text);
	QHBoxLayout *layout = new QHBoxLayout;
	layout->addWidget(textView);
	setLayout(layout);
}

void CalibrateWidget::newTextToAppend(QString text) {
	textView->setText(textView->text() + text);
}

void CalibrateWidget::contextMenuEvent(QContextMenuEvent * event) {
	QMenu *menu = new QMenu;
	QAction *saveAction = new QAction("Save");
	QObject::connect(saveAction, SIGNAL(triggered()), this, SLOT(save()));
	menu->addAction(saveAction);
	menu->exec(QCursor::pos());
	event->accept();
}

void CalibrateWidget::save() {
	QString fileName = QFileDialog::getSaveFileName(this,
		tr("Save Text"),
		"",
		tr("Plain Text (*.txt)"));
	if (!fileName.isNull())
	{
		QFile file(fileName);
		if (file.open(QIODevice::ReadWrite)) {
			QTextStream stream(&file);
			stream << textView->text() << endl;
		}
		//my_image.save(fileName);
	}
	else
	{
		return;
	}
}